from src import db
from src.models.base_model import BaseModel


class CreditCard(BaseModel):
    __tablename__ = "credit_cards"

    id = db.Column(db.Integer, primary_key=True, info="主键")
    card_no = db.Column(db.String(128, "utf8mb4_bin"), nullable=False, unique=True, info="卡号")
    belong_bank = db.Column(db.Integer, nullable=False, info="归属行")
    card_name = db.Column(db.String(255, "utf8mb4_bin"), info="卡名")
    active_date = db.Column(db.DateTime, info="激活日期")
    day_of_bill = db.Column(db.Integer, info="账单日")
    day_of_pay = db.Column(db.Integer, info="还款日")

    def to_dict(self):
        print("self", self)
        return {
            "id": self.id,
            "status": self.status,
            "card_no": self.card_no,
            "belong_bank": self.belong_bank,
            "card_name": self.card_name,
            "active_date": self.active_date,
            "day_of_bill": self.day_of_bill,
            "day_of_pay": self.day_of_pay,
            "gmt_create": self.gmt_create.strftime("%Y-%m-%d %H:%M:%S") if self.gmt_create else None,
            "gmt_modified": self.gmt_modified.strftime("%Y-%m-%d %H:%M:%S") if self.gmt_modified else None,
        }
